class IdleContext {
  final bool force;
  final String chatRoomId;
  final CloseReason closeReason;

  IdleContext({ required this.force, required this.chatRoomId, this.closeReason = CloseReason.NONE });
}

enum CloseReason {
  NONE("NONE"), // 无
  ACCEPT_TIME_OUT("ACCEPT_TIME_OUT"), // 请求超时
  NETWORK_ERROR("NETWORK_ERROR"), // 网络出错
  REJECT("REJECT"), // 拒接
  USER_EXIT("USER_EXIT"), // 有用户退出
  USER_BUSY("USER_BUSY"), // 对方忙
  USER_NOT_ONLINE("USER_NOT_ONLINE"), // 对方不在线
  HAND_UP("HAND_UP") // 用户自动终止拨打
  ; 

  const CloseReason(this.name);

  final String name;

  static CloseReason fromName(String name) {
    switch (name) {
      case "NONE": return CloseReason.NONE;
      case "ACCEPT_TIME_OUT": return CloseReason.ACCEPT_TIME_OUT;
      case "NETWORK_ERROR": return CloseReason.NETWORK_ERROR;
      case "REJECT": return CloseReason.REJECT;
      case "USER_EXIT": return CloseReason.USER_EXIT;
      case "USER_BUSY": return CloseReason.USER_BUSY;
      case "USER_NOT_ONLINE": return CloseReason.USER_NOT_ONLINE;
      case "HAND_UP": return CloseReason.HAND_UP;
      default: return CloseReason.NONE;
    }
  }
}
